<template>
  <div>
    <nav-bar title="个人资料" />
    <div class="content_scroll">
      <data-info @show-click="showClick" :userinfo="userinfo" />
      <security-info :userinfo="userinfo" />
      <div class="log-out" @click="outClick">退出登录</div>
    </div>
    <van-overlay :show="isShow" @click="show = false" />
    <!-- <div class="mask" v-show="isShow" @click="isShow = false"></div> -->
    <div class="dlg" v-show="isShow">
      <div class="dlg-title">修改昵称</div>
      <van-field
        type="text"
        placeholder="修改昵称"
        class="input"
        v-model="username"
      />
      <div class="dlg-btn">
        <span class="cancel" @click="closeClick">取消</span>
        <span class="determine" @click="changeUserName">确定</span>
      </div>
    </div>
    <van-popup v-model="outShow" round>
      <div class="out_header_title">提示</div>
      <div class="out_content">确认退出吗?</div>
      <div class="out_footer">
        <div class="out_button_cancel" @click="outShow = false">取消</div>
        <div class="out_button_confirm" @click="confirmClick">确认</div>
      </div>
    </van-popup>
  </div>
</template>

<script>
import NavBar from "../../../components/common/navbar/NavBar.vue";
import DataInfo from "./childComps/DataInfo.vue";
import SecurityInfo from "./childComps/SecurityInfo.vue";
// import {getMyInfo} from '../../../network/my'
// import {getPostJson} from '../../../network/post'
import { Toast } from "vant";
export default {
  components: {
    NavBar,
    DataInfo,
    SecurityInfo,
  },
  data() {
    return {
      isShow: false,
      userinfo: {},
      username: "",
      outShow: false,
    };
  },
  created() {
    this.getUserInfo();
  },
  methods: {
    getUserInfo() {
      this.axios.get("/userinfo.json", {}).then((res) => {
        this.userinfo = res.data.userinfo;
      });
    },
    showClick() {
      this.isShow = true;
    },
    changeUserName() {
      var url = "/user_nick_apply";
      var data = { nickname: this.username, is_ajax: 1 };
      getPostJson(url, data).then((res) => {
        console.log(res);
        if (res.status == "ok") {
          this.isShow = false;
          this.$store.commit("makeUserName", this.username);
          Toast("昵称修改成功");
        } else {
          this.isShow = false;
          Toast(res.info);
        }
        this.username = "";
      });
    },
    closeClick() {
      this.isShow = false;
      this.username = "";
    },
    outClick() {
      this.outShow = true;
    },
    confirmClick() {
      //
      axios({
        url: "/logout?json=1",
      }).then((res) => {
        this.getMyCenter();
        this.$store.commit("$_removeStorage");
        this.$store.commit("deleteUserInfo", "");
        this.$router.replace("/my");
      });
    },
    getMyCenter() {
      getMyInfo().then((res) => {
        console.log(res);
        this.userInfo = res.userinfo;
      });
    },
  },
};
</script>

<style lang="less" scoped>
.set-up {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  overflow: scroll;
  -webkit-overflow-scrolling: touch;
  height: 100vh;
  background: #f3f3f3;
}
.nav-bar {
  width: 100%;
  height: 1.173333rem;
  box-sizing: border-box;
  padding: 0 0.426667rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #ffffff;
}

.nav-icon {
  width: 1.76rem;
}

.nav-title {
  flex: 1;
  text-align: center;
  line-height: 1.173333rem;
  font-size: 0.48rem;
  font-weight: 700;
  color: #222222;
}

.nav-btn {
  width: 1.76rem;
}

.log-out {
  width: 10rem;
  height: 1.333333rem;
  background: #ffffff;
  font-size: 0.346667rem;
  font-weight: 400;
  text-align: center;
  color: #ff5543;
  line-height: 1.333333rem;
  margin-top: 0.266667rem;
}

.mask {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.7);
}

.dlg {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 7.253333rem;
  height: auto;
  background: #ffffff;
  border-radius: 0.346667rem;
}

.dlg-title {
  font-size: 0.373333rem;
  font-weight: 400;
  text-align: center;
  color: #222222;
  line-height: 1.466667rem;
}

.dlg .input {
  display: block;
  outline: none;
  width: 6.266667rem;
  height: 1.066667rem;
  margin: 0 auto;
  background: #f8f8f8;
  border: 0.013333rem solid #bebebe;
  border-radius: 0.226667rem;
  text-indent: 0.266667rem;
  font-size: 0.32rem;
  color: #999999;
  padding: 0;
  padding-left: .266667rem;
  line-height: 1.066667rem;
}

.dlg-btn {
  position: relative;
  margin-top: 0.4rem;
  border-top: 0.013333rem solid #ebebeb;
  display: flex;
  align-items: center;
  height: 1.2rem;
  text-align: center;
  font-size: 0.373333rem;
}
.dlg-btn::before {
  content: "";
  width: 0.013333rem;
  height: 0.666667rem;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #ebebeb;
}

.dlg-btn span {
  flex: 1;
}

.cancel {
  color: #288dff;
}

.determine {
  color: #eb5445;
}

.van-overlay {
  z-index: 1;
}

.dlg {
  z-index: 2;
}

.out_header_title {
  width: 7.2rem;
  height: 1.173333rem;
  line-height: 1.173333rem;
  font-size: 0.48rem;
  font-weight: 700;
  text-align: center;
}

.out_content {
  padding: 0.266667rem 0 0.8rem 0;
  text-align: center;
  font-size: 0.373333rem;
}

.out_footer {
  position: relative;
  height: 1.173333rem;
  display: flex;
  align-items: center;
  font-size: 0.426667rem;
  color: #288dff;
  border-top: 0.013333rem solid #cfcfcf;
}

.out_footer::before {
  content: "";
  width: 0.013333rem;
  height: 0.666667rem;
  background: #cfcfcf;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.out_button_cancel,
.out_button_confirm {
  flex: 1;
  text-align: center;
}
</style>